<template>

	<view class="uni-common-pb uni-padding-wrap uni-common-mt">
		<view>
			登陆状态：作业人员无需登陆。
		</view>
		<!-- #ifndef H5 -->
		<button type="primary" @tap="doQRcode">扫描工单(操作员)</button>
		<button type="primary" @tap="doQRcode_pb">扫描工单(品保)</button>
		<!-- #endif -->
		
		<button type="primary" @tap="inputWOcode">输入工单(操作员)</button>
		<button type="primary" @tap="inputWOcode_pb">输入工单(品保)</button>
	
		<button type="primary" @tap="loginTO">管理员登陆</button>

		<!-- #ifdef MP-WEIXIN -->
		<button type="primary" @tap="setting">设置</button>
		<!-- #endif -->

		<view class="uni-form-item uni-row">
			<view>
				当前制程： {{step_name}}&nbsp;&nbsp;{{step_code}}
			</view>
			<view style="padding:0 110upx">
				当前版本： {{version}}
			</view>
		</view>

		<prompt :visible.sync="promptVisible" title="工单编号" placeholder="请输入工单" defaultValue="" mainColor="#e74a39" @confirm="clickPromptConfirm">
			<!-- 这里放入slot内容-->
			<text></text>
		</prompt>
	</view>



</template>

<script>
	import Prompt from '@/components/zz-prompt/index.vue'

	export default {
		components: {
			Prompt,
		},
		data() {
			return {
				version: 11,
				step_code: '',
				step_name: '',
				promptVisible: false,
				ispb: 0,
			};
		},
		// /相应右上角的功能按钮/
		onNavigationBarButtonTap(e) {
			uni.navigateTo({
				url: '../serversetting/serversetting'
			});
		},
		onLoad: function() {
			// #ifdef APP-PLUS
			this.AndroidCheckUpdate();
			// #endif
		},
		onShow: function() {
			console.log('onShow');
			this.promptVisible = false;
			this.ispb = 0;
			console.log(this.promptVisible);
			uni.getStorage({
				key: 'zcdh',
				success: (res) => {
					this.step_code = res.data;
					console.log(res.data);
				},
				fail: () => {

				}
			});
			uni.getStorage({
				key: 'zcname',
				success: (res) => {
					this.step_name = res.data;
					console.log(res.data);
				},
				fail: () => {

				}
			});

			if (this.step_code == "") {
				// 				uni.navigateTo({
				// 					url: '../serversetting/serversetting'
				// 				});
				this.step_code = "Q1";
				this.step_name = "全检";

				uni.setStorage({
					key: 'zcdh',
					data: this.step_code,
					success: (res) => {

					},
					fail: () => {

					}
				});
				uni.setStorage({
					key: 'zcname',
					data: this.step_name,
					success: (res) => {

					},
					fail: () => {

					}
				});
			}
		},
		methods: {
			AndroidCheckUpdate: function() {
				var _this = this;
				uni.request({
					//版本自动升级也使用内网ip
					url: this.neiUrl + '/version.txt',
					method: 'GET',
					data: {},
					success: res => {
						if (res.data > this.version) {
							if (plus.networkinfo.getCurrentType() != 3) {
								uni.showToast({
									title: '有新的版本发布，检测到您目前非Wifi连接，为节约您的流量，程序已停止自动更新，将在您连接WIFI之后重新检测更新。',
									mask: false,
									duration: 5000,
									icon: "none"
								});
								return;
							}
							uni.showToast({
								title: '有新的版本发布，检测到您目前为Wifi连接，程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
								mask: false,
								duration: 5000,
								icon: "none"
							});
							var dtask = plus.downloader.createDownload(this.neiUrl + "/ccrapp.apk", {}, function(d, status) {
								// 下载完成  
								if (status == 200) {
									plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function(error) {
										uni.showToast({
											title: '安装失败',
											mask: false,
											duration: 1500
										});
									})
								} else {
									uni.showToast({
										title: '更新失败',
										mask: false,
										duration: 1500
									});
								}
							});
							dtask.start();
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			doQRcode: function() {
				let _this = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log(res.result);
						//1507-20190108001/4-5-JU060A9M6-A/UC0.6*8.5/2019-01-08 × 1,000
						var workorder = res.result.split("/", 1);
						uni.navigateTo({
							url: '../index/index?workordernumber=' + workorder,
						});
					}
				});
			},
			doQRcode_pb: function() {
				let _this = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log(res.result);
						//1507-20190108001/4-5-JU060A9M6-A/UC0.6*8.5/2019-01-08 × 1,000
						var workorder = res.result.split("/", 1);
						uni.navigateTo({
							url: '../wodetail/wodetail?workordernumber=' + workorder + "&ispb=1",
						});
					}
				});
			},
			setting: function() {
				uni.navigateTo({
					url: '../serversetting/serversetting'
				});
			},
			inputWOcode: function() {
				this.promptVisible = true;
				this.ispb = 0;
			},
			inputWOcode_pb: function() {
				this.promptVisible = true;
				this.ispb = 1;
			},
			clickPromptConfirm(val) {
				console.log(val)
				if (this.ispb == 0) {
					uni.navigateTo({
						url: '../index/index?workordernumber=' + val,
					});
				} else {
					uni.navigateTo({
						url: '../wodetail/wodetail?workordernumber=' + workorder + "&ispb=1",
					});
				}
			},
			loginTO: function() {
				uni.navigateTo({
					url: '../login/login',
				});
			}
		}
	}
</script>

<style>
	button {
		margin-top: 30upx;
		margin-bottom: 30upx;
	}
</style>
